package com.liuyjy.builder;

/**
 * @Author liuyjy
 * @Date 2025/2/19 13:02
 * @Description: 建造者模式用于创建复杂对象，特别是当对象有多个可选参数时。
 **/
public class HttpRequest {
    private String method;
    private String url;
    private String body;

    private HttpRequest(Builder builder) {
        this.method = builder.method;
        this.url = builder.url;
        this.body = builder.body;
    }

    public static class Builder {
        private String method;
        private String url;
        private String body;

        public Builder method(String method) {
            this.method = method;
            return this;
        }

        public Builder url(String url) {
            this.url = url;
            return this;
        }

        public Builder body(String body) {
            this.body = body;
            return this;
        }

        public HttpRequest build() {
            return new HttpRequest(this);
        }
    }
}
